//
//  MainViewController.swift
//  SinWebo
//
//  Created by 刘大钊 on 16/4/6.
//  Copyright © 2016年 刘大钊. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabBar = MainTabBar()
        
        //KVC 给对象提供类似字典的方式 访问对象的属性
        //系统的tabBar 是只读属性 不能够直接操作
        setValue(mainTabBar, forKey: "tabBar")
        //添加所有子视图控制器
        addChildViewControllers()

      
    }
    
    private func addChildViewControllers() {
        addChildViewControllers(HomeTableViewController(),title: "首页",imageName: "tabbar_home")
        addChildViewControllers(MassageTableViewController(),title: "消息",imageName: "tabbar_message_center")
        addChildViewControllers(DiscoverTableViewController(),title: "发现",imageName: "tabbar_discover")
        addChildViewControllers(ProfileTableViewController(),title: "我",imageName: "tabbar_profile")
        
        
    }

    //MARK:添加子视图控制器
    
    private func addChildViewControllers(vc: UIViewController,title: String,imageName: String) {
        
        
        //设置title
        vc.title = title
        vc.tabBarItem.title = title
        
        //设置字体
        //        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        
        //设置tintcolor
        tabBar.tintColor = UIColor.orangeColor()
        //设置图片
        vc.tabBarItem.image = UIImage(named: imageName)
        
        //设置选中图片
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        let nav = UINavigationController(rootViewController:vc)
        

        
        addChildViewController(nav)
        
        
        
        
    }
  

}
